<?php

namespace app\admin\model;

use app\common\model\PublishComment;
use think\Model;


class PublishCommentReport extends Model
{

    

    

    // 表名
    protected $name = 'user_publish_comment_report';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;



    // 追加属性
    protected $append = [

    ];



    public function getTypeListAttr()
    {
        return (new ConfigValueModel)->getOptionList(ConfigValueModel::TYPE_REPORT);
    }


    public function getStatusList()
    {
        return [0 => '未处理', 1 => '已处理'];
    }


    public function pubComment()
    {
        return $this->belongsTo(PublishComment::class, 'comment_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id')->field('id,username');
    }

    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
